<template>
	<view class="account-security-page">
		<navigation :navigationMsg="navigationMsg"></navigation>
		<view class="main">
			<view class="list-item" v-for="(item,index) in list" :key="index" @click="listItem(item,index)">
				<view class="title">
					{{item.title}}
				</view>
				<view class="tel" v-if="item.tel">
					{{formatPhoneNumber("13905228028")}}
				</view>
				<view class="text" v-if="item.text">
					{{item.text}}
				</view>
				<view class="right-icon" v-if="item.right"></view>
			</view>
		</view>
		<u-popup :show="logoutShow" :round="10" mode="center" @close="logoutClose" @open="logoutOpen">
			<view class="logout-box">
				<view class="title">
					注销账号
				</view>

				<view class="btn-box">
					<view class="submit" @click="logoutCancel">
						取消
					</view>
					<view class="logout" style="backgroundColor:#F56C6C;" @click="logOut">
						注销 </view>

				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		http
	} from '@/api/index.js'
	import navigation from '../../../../components/navigation.vue';
	export default {
		data() {
			return {
				navigationMsg: {
					title: "账号与安全"
				},
				list: [{
					id: 2,
					title: "实名认证",
					text: "",
					right: true
				}, {
					id: 3,
					title: "注销账号",
					right: true
				}],
				logoutShow: false
			}
		},
		components: {
			navigation
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			//获取会员资料
			getUserInfo() {
				http.post('/api/account/getUserInfo').then(res => {}).catch(err => {
					this.list[0].tel = err.data.data.mobile
					if (err.data.data.verify) {
						this.list[1].text = "已实名"
					} else {
						this.list[1].text = "未实名"
					}
				})
			},
			listItem(item, index) {
				if (item.id == 3) {
					this.logoutShow = true
				} else if (item.id == 2) {
					uni.navigateTo({
						url: "/pages/my/setting/Account_Security/realName/realName"
					})
				} else {
					uni.showToast({
						title: "功能暂未开放！",
						icon: "none",
						duration: 1500
					})
				}
			},
			//关闭注销弹窗
			logoutClose() {
				this.logoutShow = false
			},
			//打开注销弹窗
			logoutOpen() {
				this.logoutShow = true
			},
			//取消注销
			logoutCancel() {
				this.logoutClose()
			},
			//注销
			logOut() {
				http.get('/api/account/logOff').then(res => {
					console.log('res', res);
					uni.clearStorage()
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}, 1500)
				}).catch(err => {
					console.log('err', err);
				})
			}
			//
			//手机号加密
			// formatPhoneNumber(phone) {
			// 	const start = phone.slice(0, 3);
			// 	const middle = '****';
			// 	const end = phone.slice(7);
			// 	return start + middle + end;
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.account-security-page {
		width: 100%;
		height: 100vh;
		background-color: #f3f3f3;

		.main {
			width: 100%;
			height: calc(100% - 100rpx);
			overflow: hidden;

			.list-item {
				width: 100%;
				height: 120rpx;
				background-color: white;
				line-height: 120rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				>.title {
					margin-left: 20rpx;
					flex: 1;
				}

				.right-icon {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
					background-image: url("../../../../static/rightArrow_black.svg");
					background-size: contain;
					background-position: center;
					background-repeat: no-repeat;
				}

				.tel,
				.text {
					margin-right: 20rpx;
					font-size: 30rpx;
					color: #7c7c7c;
				}
			}

			>.list-item:nth-child(1) {
				margin-top: 20rpx;
			}
		}

		.logout-box {
			width: 400rpx;
			height: 200rpx;
			background-color: white;
			border-radius: 30rpx;

			.title {
				width: 100%;
				text-align: center;
				margin-top: 30rpx;
				font-size: 36rpx;
				font-weight: bold;
			}

			.btn-box {
				width: 100%;
				height: 100rpx;
				margin-top: 30rpx;
				display: flex;
				justify-content: space-between;

				>view {
					width: 150rpx;
					height: 70rpx;
					border-radius: 10rpx;
					text-align: center;
					line-height: 70rpx;
					color: white;
				}

				.submit {
					background-color: #ccc;
					margin-left: 30rpx;
				}

				.logout {
					background-color: black;
					margin-right: 30rpx;
				}
			}
		}
	}
</style>